<?php
/**
 * 用户管理类
 * author: heimuya
 * time: 2014-4-15
 */
 namespace Admin\Controller;
 use Think\Controller;
 
class UserController extends CommonController {
	
	public function _initialize(){
		parent::_initialize();
	}
	
	public function glist(){
		$GL = M('Feedback');
		$count = $GL->count();
		$Page = new \Think\Page($count, 10);
		$where['uid'] = 0;
		$glist = $GL->where($where)->limit($Page->firstRow. ',' . $Page->listRows)->order('time desc')->select();
		$this->empty = "<td colspan='5' class='tb_heade'>暂无数据</td>";
		
		foreach ($glist as $key => $value) {
			$glist[$key]['content'] = (utf8_strlen($value['content']) > 20) ? utf_substr($value['content'], 40).'...' : $value['content'];
		}
		$page = $Page->show();

        $this->assign("page", $page);
		$this->assign('glist',$glist);

		$this->display();
	}
	
	public function reply(){
		$id = I('id','','int');
		if($id == ''){
			$this->error('参数错误');
		}
		$GL = M('Feedback');
		$gbook = $GL->where(array('id'=>$id))->find();
		
		$this->assign('gbook',$gbook);
		$this->display();
	}
	
	public function doreply(){
		$id = I('id','','int');
		if($id == ''){
			$this->error('参数错误');
		}
		$GL = M('Feedback');
		$gbook = $GL->where(array('id'=>$id))->find();
		
		//调用邮箱接口发送邮件
		if(!sendMail($gbook['email'], C('WEBSET.sitename').'--回复', I('reply'))){
			$this->error('邮件发送失败！');
			exit;
		}
		
		$data['uid'] = session(C('USER_AUTH_KEY'));;
		$data['content'] = "To:".$gbook['email'].":\n".I('reply');
		$data['time'] = time();
		$rs = $GL->add($data);
		if($rs){
			$data1['reply'] = 'y';
			$GL->where(array('id'=> $id))->setField($data1);
			$this->success('回复成功', U('User/glist'));
			exit;
		}else {
			$this->error('回复失败');
		}
	}
}